#include"comm.hpp"

int main()
{
    Init init;
    int shmid = CreatShm();
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);
    struct shmid_ds shmds;

    //打开信道
    int fd = open(FIFO_FILE, O_RDONLY);
    if(fd < 0)
    {
        log(Fatal, "error string: %s, error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }

    //ipc code
    while(true)
    {
        char c;
        ssize_t s = read(fd, &c, 1);
        if(s == 0) break;
        else if(s < 0) break;
        //直接访问共享内存
        cout<<"client say: "<<shmaddr<<endl;
        sleep(1);

        shmctl(shmid, IPC_STAT, &shmds);
        cout<<"shm segsz:"<<shmds.shm_segsz<<endl;
        cout<<"shm nattch:"<<shmds.shm_nattch<<endl;
        cout<<"shm key:"<<shmds.shm_perm.__key<<endl;
        cout<<"shm mode:"<<shmds.shm_perm.mode<<endl;

    }

    shmdt(shmaddr);
    shmctl(shmid, IPC_RMID, nullptr);


    close(fd);
    return 0;
}